package org.itboys.core.controller.web.company;

import org.itboys.admin.tools.AdminSessionHolder;
import org.itboys.core.entity.mongo.SundayMember;
import org.itboys.core.entity.mysql.wallet.record.SundayWalletRecord;
import org.itboys.core.service.mongo.web.SundayMemberService;
import org.itboys.core.service.mysql.web.SundayCompanyWalletService;
import org.itboys.core.util.MybatisParamUtil;
import org.itboys.framework.query.JsonPageUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.param.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;

/**
 * @Author：贾琦磊
 * @Date：2019/1/7
 * @Description：
 */
@Controller
@RequestMapping("/sunday/web/company/wallet")
public class SundayCompanyWalletController extends BaseController{
    @Autowired
    private SundayCompanyWalletService walletService;
    @Autowired
    private SundayMemberService memberService;
    @RequestMapping("/index")
    public String index(HttpServletRequest request, HttpServletResponse response){
        return "sunday/company/wallet/index";
    }
    @RequestMapping("/select")
    public void select(HttpServletRequest request, HttpServletResponse response
    , @RequestParam(value = "createTime_start",required = false)Date ct_start
    , @RequestParam(value = "createTime_end",required = false)Date ct_end){
        Long userId = AdminSessionHolder.getAdminUserId();
        SundayMember member = memberService.getMemberByUserId(userId);
        PageResult<SundayWalletRecord> result = walletService.select(new MybatisParamUtil(request), member.getId(),ct_start,ct_end);
        JsonPageUtils.renderJsonPage(result.getTotal(), result.getData(), response);
    }
}
